package cn.luischen.controller;

import cn.luischen.constant.ErrorConstant;
import cn.luischen.constant.Types;
import cn.luischen.constant.WebConst;
import cn.luischen.dto.ArchiveDto;
import cn.luischen.dto.cond.ContentCond;
import cn.luischen.exception.BusinessException;
import cn.luischen.model.CommentDomain;
import cn.luischen.model.ContentDomain;
import cn.luischen.service.comment.CommentService;
import cn.luischen.service.content.ContentService;
import cn.luischen.service.meta.MetaService;
import cn.luischen.service.option.OptionService;
import cn.luischen.service.site.SiteService;
import cn.luischen.utils.*;
import com.github.pagehelper.PageInfo;
import com.vdurmont.emoji.EmojiParser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.junit.Rule;
import org.junit.runner.RunWith;
import org.junit.rules.ExpectedException;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.mockito.stubbing.Answer;
import java.lang.reflect.Method;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.ParserConfig;
import java.util.Map;
import java.util.List;
import com.unitspirit.runtime.*;

/**
 * The class contains tests for the class cn.luischen.controller.HomeController.
 *
 * @generatedBy UnitSpirit CreateTemplateTestFile4
 * @version 1.0.9.11 
 */
@PowerMockIgnore({ "javax.management.*" })
@RunWith(PowerMockRunner.class)
@PrepareForTest({ cn.luischen.controller.HomeController.class,
		cn.luischen.utils.TaleUtils.class,
		cn.luischen.model.CommentDomain.class,
		cn.luischen.utils.APIResponse.class, cn.luischen.utils.IPKit.class })
public class HomeController_comment_WGTest {
	@Rule
	public ExpectedException unitspirit_thrown = ExpectedException.none();

	/**
	 * 测试方法初始化.
	 * 
	 * @throws Exception 
	 *         if the initialization fails for some reason 
	 *  
	 * @generatedBy UnitSpirit at 2021-12-08 11:01:07
	 */
	@org.junit.Before
	public void setUp() throws Exception {
		try {
			GlobalUnitInit.init();
			MockitoAnnotations.initMocks(this);
			ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	@InjectMocks
	cn.luischen.controller.HomeController unitspirit_fixture;

	@Mock
	cn.luischen.service.comment.CommentService mock_CommentService;
	@Mock
	cn.luischen.service.site.SiteService mock_SiteService;
	@Mock
	cn.luischen.service.option.OptionService mock_OptionService;
	@Mock
	cn.luischen.service.content.ContentService mock_ContentService;
	@Mock
	cn.luischen.service.meta.MetaService mock_MetaService;

	/**
	 * @date 2021-12-08 11:01:08
	 * @see cn.luischen.controller.HomeController#comment
	 * @category null  
	 * @author UnitSpirit   
	 */
	@Test
	public void test_comment_1207_113909_364_2_01() throws Throwable {
		unitspirit_fixture = PowerMockito.spy(unitspirit_fixture);
		//被测函数参数定义
		javax.servlet.http.HttpServletRequest HttpServletRequest_p_0 = Mockito
				.mock(javax.servlet.http.HttpServletRequest.class);
		javax.servlet.http.HttpServletResponse HttpServletResponse_p_1 = Mockito
				.mock(javax.servlet.http.HttpServletResponse.class);
		Integer Integer_p_2 = 27;
		Integer Integer_p_3 = null;
		String String_p_4 = "111";
		String String_p_5 = "11@qq.com";
		String String_p_6 = "";
		String String_p_7 = "123123123";
		String String_p_8 = "055icXW7IaqrsGKw7tguZ1";
		//成员变量设置

		//返回值定义 
		String result_expected = "{\"code\":\"success\"}";
		cn.luischen.utils.MapCache mock_sub_caller_MapCache19 = PowerMockito
				.mock(cn.luischen.utils.MapCache.class);
		String mock_result_String19 = "\"/blog/article/27\"";
		PowerMockito.mockStatic(cn.luischen.utils.TaleUtils.class);
		java.lang.Boolean mock_result_Boolean18 = true;
		PowerMockito.mockStatic(cn.luischen.utils.IPKit.class);
		java.lang.String mock_result_String17 = "\"127.0.0.1\"";
		java.lang.String mock_result_String15 = "\"111\"";
		java.lang.String mock_result_String14 = "\"123123123\"";
		cn.luischen.model.CommentDomain mock_sub_caller_CommentDomain13 = PowerMockito
				.mock(cn.luischen.model.CommentDomain.class);
		String Stringmock12_0 = "111";
		Integer Integermock11_0 = 27;
		String Stringmock10_0 = "127.0.0.1";
		String Stringmock9_0 = "";
		String Stringmock8_0 = "123123123";
		String Stringmock7_0 = "11@qq.com";
		Integer Integermock6_0 = null;
		cn.luischen.model.CommentDomain CommentDomainmock5_0 = JSON
				.parseObject(
						"{\"mail\":\"11@qq.com\",\"author\":\"111\",\"created\":1607312348,\"ip\":\"127.0.0.1\",\"content\":\"123123123\",\"url\":\"\",\"cid\":27,\"status\":\"not_audit\"}",
						cn.luischen.model.CommentDomain.class);
		String Stringmock4_0 = "tale_remember_author";
		String Stringmock4_1 = "111";
		int intmock4_2 = 604800;
		javax.servlet.http.HttpServletResponse HttpServletResponsemock4_3 = Mockito
				.mock(javax.servlet.http.HttpServletResponse.class);
		String Stringmock3_0 = "tale_remember_mail";
		String Stringmock3_1 = "11%40qq.com";
		int intmock3_2 = 604800;
		javax.servlet.http.HttpServletResponse HttpServletResponsemock3_3 = Mockito
				.mock(javax.servlet.http.HttpServletResponse.class);
		String Stringmock2_0 = "comments:frequency";
		String Stringmock2_1 = "127.0.0.1:27";
		Object Objectmock2_2 = "1";
		long longmock2_3 = 60L;
		PowerMockito.mockStatic(cn.luischen.utils.APIResponse.class);
		cn.luischen.utils.APIResponse mock_result_APIResponse1 = JSON
				.parseObject("{\"code\":\"success\"}",
						cn.luischen.utils.APIResponse.class);

		PowerMockito.when(
				mock_sub_caller_MapCache19.hget(anyString(), anyString()))
				.thenReturn(mock_result_String19);
		PowerMockito.when(cn.luischen.utils.TaleUtils.isEmail(anyString()))
				.thenReturn(mock_result_Boolean18);
		PowerMockito.when(
				cn.luischen.utils.IPKit.getIpAddrByRequest(Mockito
						.any(javax.servlet.http.HttpServletRequest.class)))
				.thenReturn(mock_result_String17);
		PowerMockito.doReturn(null).when(mock_sub_caller_MapCache19, "hget",
				anyString(), anyString());
		PowerMockito.when(cn.luischen.utils.TaleUtils.cleanXSS(anyString()))
				.thenReturn(mock_result_String15)
				.thenReturn(mock_result_String14);
		PowerMockito.whenNew(cn.luischen.model.CommentDomain.class)
				.withNoArguments().thenReturn(mock_sub_caller_CommentDomain13);
		PowerMockito.doNothing().when(mock_sub_caller_CommentDomain13)
				.setAuthor(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_CommentDomain13)
				.setCid(Mockito.anyInt());
		PowerMockito.doNothing().when(mock_sub_caller_CommentDomain13)
				.setIp(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_CommentDomain13)
				.setUrl(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_CommentDomain13)
				.setContent(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_CommentDomain13)
				.setMail(anyString());
		PowerMockito.doNothing().when(mock_sub_caller_CommentDomain13)
				.setParent(Mockito.any());
		PowerMockito.doNothing().when(mock_CommentService)
				.addComment(Mockito.any(cn.luischen.model.CommentDomain.class));
		PowerMockito.doNothing().when(mock_sub_caller_MapCache19)
				.hset(anyString(), anyString(), anyObject(), Mockito.anyLong());
		PowerMockito.when(cn.luischen.utils.APIResponse.success()).thenReturn(
				mock_result_APIResponse1);

		cn.luischen.utils.APIResponse unitspirit_result = unitspirit_fixture
				.comment(HttpServletRequest_p_0, HttpServletResponse_p_1,
						Integer_p_2, Integer_p_3, String_p_4, String_p_5,
						String_p_6, String_p_7, String_p_8);
		cn.luischen.utils.APIResponse obj_expected = JSON.parseObject(
				result_expected, cn.luischen.utils.APIResponse.class);
		UnitAssert.assertEquals(
				UnitSpiritFastJsonUtil.getJsonString2(obj_expected),
				UnitSpiritFastJsonUtil.getJsonString2(unitspirit_result));
	}
}
